package com.itheima.reggie.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.reggie.entity.Category;
import com.itheima.reggie.service.CategoryService;
import com.itheima.reggie.utils.Result;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/category")
public class CategoryController {

    @Resource
    private CategoryService categoryService;

    @PostMapping
    public Result<String> addOne(@RequestBody Category category){
        return categoryService.addOne(category);
    }

    @GetMapping("/page")
    public Result<Page<Category>> getPage(int page,int pageSize){
        return categoryService.getPage(page,pageSize);
    }

    @DeleteMapping
    public Result<String> deleteOne(Long ids){
        return categoryService.deleteOne(ids);
    }

    @PutMapping
    public Result<String> updateById(@RequestBody Category category){
        return categoryService.updateById(category);
    }

    @GetMapping("/list")
    public Result<List<Category>> list(Category category){
        return categoryService.list(category);
    }
}
